<template>
	<view class="employee_box">
		<view class="topPart">
			<view class="searchBox2 w dpflxr">
				<view class="icon">
					<image
						src="https://babybear-fx.oss-cn-shenzhen.aliyuncs.com/VIPxcx/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E5%9B%BE%E7%89%87/icon_search.png">
					</image>
				</view>
				<input class="inputBox" @confirm="search" type="text" confirm-type="search" placeholder="请输入手机号"
					placeholder-style="font-size:24rpx; line-height:60rpx;color:#999;"></input>
			</view>
		</view>
		<view class="card w emItem" v-for="(item, index) in list">
			<view class="title_box4 wp">
				<view class="tb_left">
					<view v-if="item.avatar==null">
					<view class="avatar">
							<image
								src="../../static/images/img11.png"
								mode="aspectFill"
								></image>
					</view>
					</view>
					<view v-else>
					<view class="avatar">
							<image
								:src="item.avatar"
								mode="aspectFill"
								
								></image>
					</view>
					</view>
				</view>
				<view class="words">
					<view class="dpflxrjb">
						<text class="name">{{ item.firstname }}{{ item.lastname }}</text>
						<view class="dpflxr" @click="callPhone(item.mobile)">
							<view class="icon">
								<image src="../../static/images/icon_phone.png"></image>
							</view>
							<text class="tel">{{ item.mobile }}</text>
						</view>
					</view>
					<text class="rights">权限 : {{item.auths}}</text>
				</view>

			</view>
			<view class="btnBox dpflxr">
				<!-- <view class="btn">重置密码</view> -->
				<navigator :url="'../index_employee_rights/index_employee_rights?id=' + item.id" class="btn">设置权限</navigator>
				<navigator :url="'../index_employee_check/index_employee_check?id=' + item.id" class="btn highlight">业绩查看</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	import request from "@/api/index.js";

	export default {
		data() {
			return {
				page: 1,
				mobile: '',
				list: []
			}
		},

		onLoad() {
			var page = 1,
				mobile = '';

			this.getList(page, mobile, list => {
				if (list.length > 0) {
					this.list = list;
				} else {
					uni.showToast({
						title: '暂无更多数据',
						icon: 'none'
					})
				}
			});
		},

		onReachBottom() {
			var list = this.list;
			var page = this.page;
			var mobile = this.mobile;
			var incPage = ++page;

			this.getList(page, mobile, list_data => {
				if (list_data.length > 0) {
					list_data.forEach(function(val) {
						list.push(val)
					})

					this.list = list;
					this.page = incPage;
				} else {
					uni.showToast({
						title: '暂无更多数据',
						icon: 'none'
					})
				}
			});
		},

		methods: {
			getList: function(page = 1, mobile = '', callback) {
				var url = '/shop/store-api/'+uni.getStorageSync('shop_id')+'/shopinfo/getShopEmployees?mobile=' + mobile + '&current=' + page
				request.http(url, 'GET').then(res => {
					var data = res.data;
					if (data.code == 0) {
						var list = data.data.records;
						callback(list);
					}
				})
			},

			search: function(e) {
				var mobile = e.detail.value;
				var page = 1;

				this.mobile = mobile;
				this.page = page;

				this.getList(page, mobile, list => {
					if (list.length > 0) {
						this.list = list;
					} else {
						this.list = [];
						uni.showToast({
							title: '暂无更多数据',
							icon: 'none'
						})
					}
				})
			},
			callPhone(tel){
				uni.makePhoneCall({
					phoneNumber: tel,
					success: () => {
						console.log("成功拨打电话")
					},
					fail: () => {
						
					}
				})
			}
			
		}
	}
</script>

<style src="../../static/css/app.css"></style>
<style>
	.card {
		border-radius: 20rpx;
	}

	.topPart {
		background-color: #FFFFFF;
		padding: 20rpx 0rpx;
	}

	.emItem {
		box-sizing: border-box;
		padding: 30rpx 0rpx 0 0rpx;
	}

	.emItem .title_box4 {
		padding-bottom: 30rpx;
		border-bottom: 1rpx #eee solid;
	}

	.emItem .title_box4 .tb_left .avatar {
		width: 100rpx;
		height: 100rpx;
	}

	.emItem .title_box4 .words {
		width: calc(100% - 120rpx);
	}

	.emItem .title_box4 .words .name {
		font-size: 28rpx;
		font-weight: bold;
		color: #333333;
		line-height: 28rpx;
	}

	.emItem .title_box4 .words .icon {
		width: 36rpx;
		height: 36rpx;
		margin-right: 20rpx;
	}

	.emItem .title_box4 .words .rights {
		font-size: 24rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #999999;
		margin-top: 20rpx;
	}

	.emItem .btnBox {
		width: 100%;
		padding: 20rpx;
		justify-content: flex-end;
		box-sizing: border-box;
	}

	.emItem .btnBox .btn {
		width: 120rpx;
		height: 48rpx;
		border: 1rpx solid #DDDDDD;
		border-radius: 12rpx;
		text-align: center;
		line-height: 48rpx;
		color: #999;
		margin-left: 20rpx;
		font-size: 20rpx;
	}

	.emItem .btnBox .btn.highlight {
		background: #F9600D;
		color: #FFFFFF;
	}
</style>
